﻿using MediatR;
using ProductionLine.API.Application.Command.PlanDetail.Read;
using ProductionLine.Domain.Material;
using ProductionLine.ErrorCode;
using ProductionLine.Infrastructure.Interface;

namespace ProductionLine.API.Application.Handler.PlanDetail.Read
{
    public class GetMaterialDetailHandler : IRequestHandler<GetMaterialDetailCommand, APIResult<List<MaterialDetailIModel>>>
    {
        IBaseRepository<MaterialDetailIModel> materRepo;

        public GetMaterialDetailHandler(IBaseRepository<MaterialDetailIModel> materRepo)
        {
            this.materRepo = materRepo;
        }

        public Task<APIResult<List<MaterialDetailIModel>>> Handle(GetMaterialDetailCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<MaterialDetailIModel>> res=new APIResult<List<MaterialDetailIModel>>();
            var materialist=materRepo.GetAll().Where(c=>!c.IsDel).ToList();
            res.Code = APIEnum.Success;
            res.Msg = "物料明细查询成功";
            res.Data = materialist;
            return Task.FromResult(res);
        }
    }
}
